package ui.loading
{

	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.ProgressEvent;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	/**
	 * 加载条
	 */
	public class Loading extends Sprite
	{
		public function Loading()
		{
			super();
			this._width=800;
			createChildren();
		}
		
		public function set info(value:String):void
		{
			_info.text = value;
		}

		/**
		 * 处理事件
		 */
		public function onProgress(e:ProgressEvent):void
		{
			if(this._info)
			{
				var p:Number=e.bytesLoaded/e.bytesTotal;
				_info.text=p*100+"%";
				var rect:Rectangle=new Rectangle(0,0,_bitdata.width*p,_bitdata.height);
				_bitdata.fillRect(rect,0xffff0000);//血条
			}
		}
		
		//protected
		protected  function createChildren():void
		{
			_info=new TextField();
			_info.defaultTextFormat=new TextFormat(null,12,0xf0f034);
//			_info.text="看那部看的奥";
			_bitmap=new Bitmap();
			_bitmap.y=24;
			_bitdata=new BitmapData(this._width,30,false,0xf8cacbc);
			_bitmap.bitmapData=_bitdata;
			_bitmap.width=_width;
			_bitmap.height=30;
			this.addChild(_info);
			this.addChild(_bitmap);
		}
		
		

		//成员
		private var _width:Number;
		private var _info:TextField;
		private var _bitmap:Bitmap;
		private var _bitdata:BitmapData;
	}
}